#incoding=utf-8
from django.http import HttpResponseRedirect, HttpResponse
from django.template import Context, loader
from django.shortcuts import render_to_response

from pydemo.book.models import Sort, Book

import datetime

def save(request, pagename):
    now = datetime.datetime.now()
    
    money = request.Post['money']
    describe = request.Post['describe']
    item = request.Post['item']
    date = request.Post[now]
    
    pages = book.objects.filter(pagename=pagename)
    
    if pages:
        pages[0].money = money
        pages[0].describe = describe 
        pages[0].item = item
        pages[0].date = date 
        pages[0].save()
    else:
        page = book(pagename=pagename, money=money, describe=describe, item=item, date=date)
        page.save()
    return HttpResponseRedirect('/book/%s' % pagename)